$(function(){
    init_rece_tracnce();
});
/**初始化部门列表*/
function init_rece_tracnce(){
    $.post(ctx+"dept/getUseeAndDepttree",{},function (r) {
        var array  = r.msg;
        $("#using_json").jstree({
            "core": {"multiple": false,"data":array},
            "checkbox" : {"keep_selected_style" : false},
            "plugins" : [ "wholerow", "checkbox" ]
        });
        // 获得点击节点的id
        $('#using_json').on("changed.jstree", function (e, data) {
            var nodeid = data.node.id;
            var text = data.node.text;
            var action = data.action;
            if (action == "deselect_node") {
                $("#user-selectfor").find("div").each(function () {var data_id = $(this).attr("data-id");if (data_id == nodeid) $(this).remove();});
            }else{
                var label = "<div class='label label-danger p-3 m-3 pull-left' data-id='"+nodeid+"'>"+text+"</div>";$("#user-selectfor").empty().append(label);}
        });
    });
}
/**点击转让客户的跟踪人员**/
function clickSuretrance() {
    var ids = $("#saleCustReceTable").bootstrapTable("getSelections");
    var ids_arr = "";
    if (!ids.length) {$JuXue.n_warning("请勾选需要导出的领取客户信息！");return;}
    for (var i = 0; i < ids.length; i++) {ids_arr += ids[i].dyCusUuid;if (i !== (ids.length - 1)) ids_arr += ",";}
    /**记录转让的人员**/
    var useridsArray = new Array();
    $("#user-selectfor").find("div").each(function () {var notselect = $(this).attr("data-id");useridsArray.push(notselect);});
    if (!useridsArray.length) {$JuXue.n_warning("请选择需要转让的用户信息！");return;}
    var bpDistribute = useridsArray.join(",");
    $("#receTranceModal").modal("hide");
    $.post(ctx+"seaExtension/batchUpdateExEmp",{"ids":ids_arr,cExCustomer:bpDistribute},function (r) {
        if (r.code == 0){
            $JuXue.n_success("转让成功");$(".theme-panel").removeClass("active").addClass("hidden");$JuXue.refreshTable('saleCustReceTable')
        }else{$JuXue.n_warning("转让失败");}
    });
}
